package com.buanalintas.sandals.pos.color;

import com.buanalintas.bynga.Controller;
import com.buanalintas.bynga.Dictionary;
import com.buanalintas.bynga.Field;
import com.buanalintas.bynga.Page;
import com.buanalintas.sandals.pos.entities.PosMasterColor;

public class Color extends Page {

    private Field colorId;
    private Field colorCode;
    private Field colorName;

    public Color() {
        setTheClass(PosMasterColor.class);

        colorId = new Field();
        colorId.setName("colorId");
        colorId.setCaption("id");
        colorId.setListProperties(" align=\"right\" width=\"5%\" nowrap");
        colorId.setInputProperties(" size=\"20\"");
        getFields().add(colorId);

        colorCode = new Field();
        colorCode.setName("colorCode");
        colorCode.setCaption("code");
        colorCode.setListProperties(" align=\"center\" width=\"10%\" nowrap");
        colorCode.setInputProperties(" size=\"20\"");
        getFields().add(colorCode);

        colorName = new Field();
        colorName.setName("colorName");
        colorName.setCaption("name");
        colorName.setListProperties(" align=\"left\" width=\"80%\" nowrap");
        colorName.setInputProperties(" size=\"30\"");
        colorName.setRequired(true);
        colorName.setInputCase(Field.CASE_UPPER);
        getFields().add(colorName);

        fillFields();
        
        setController(new ColorController(this));

        getFieldsUnique().add(new Field[]{colorCode});

        getFieldsAdd().remove(colorId);
        getFieldsEdit().remove(colorId);
        getFieldsList().remove(colorId);
        
        setExportList(getClass().getResourceAsStream("ColorList.jasper"));
        setExport(getClass().getResourceAsStream("Color.jasper"));
        getController().setOrder(colorCode);
    }

    class ColorController extends Controller {

        public ColorController(Page page) {
            super(page);
            setOrder(colorName);
            setOrderType("DESC");
        }

        @Override
        public void beforeUpdate(Object data) {
            System.out.println("Before Update");
        }

        @Override
        public void afterUpdate(Object data) {
            System.out.println("After Update");
        }
        
        
    }
    @Override
    public void beforeExport() {
        getExportParams().put("title", Dictionary.getValue(this, "Color"));
    }

    @Override
    public void beforeExportMulti() {
        beforeExport();
    }
}
